using System.Collections.Generic;
using BruteForce.UserInterface.Abstracts;
using BruteForce.Utilities;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace BruteForce.NewManagers
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class UIControlManager : Manager
    {
        public static UIControlManager Instance = new UIControlManager();
        public Texture2D BlackStoneTexture;
        public Texture2D CreateAndPlaceButtonTexture;
        public Texture2D CreateAndPlacePressedButtonTexture;
        public Texture2D CancelButtonTexture;
        public Texture2D DismissButtonTexture;
        public Texture2D DismissPressedButton;
        public Texture2D ResumePressedButtonTexture;
        public Texture2D ResumeButtonTexture;
        public Texture2D CreateNewUnitButtonTexture;
        public Texture2D CreateNewUnitPressedButtonTexture;

        public Texture2D BlackLogoTexture;
        public Texture2D WhiteLogoTexture;



        public Texture2D ShootButtonTexture;
        public Texture2D ShootPressedButtonTexture;

        public Texture2D WalkButtonTexture;
        public Texture2D WalkPressedButtonTexture;

        public Texture2D EndTurnButtonTexture;
        public Texture2D EndTurnButtonPressedTexture;
       
        public AbstractUIControl CurrentFocuseOn;
        public MonitoredProperty<AbstractUIControl> CurrentUIControl = new MonitoredProperty<AbstractUIControl>(null);

        public Texture2D GreyStoneTexture;
        public Texture2D HumanPlayerTexture;
        public Texture2D MonsterPlayerTexture;
        public Texture2D HumanPlayerSmallIconTexture;
        public Texture2D MonsterPlayerSmallIconTexture;
        public Texture2D SliderBackgroundTexture;
        public Texture2D SliderScrollBarTexture;
        public Texture2D HumanArcherButtonTexture;
        public Texture2D HumanBomberButtonTexture;
        public Texture2D HumanDefenderButtonTexture;
        public Texture2D HumanArcherPressedButtonTexture;
        public Texture2D HumanBomberPressedButtonTexture;
        public Texture2D HumanDefenderPressedButtonTexture;
        public Texture2D MonsterArcherButtonTexture;
        public Texture2D MonsterBomberButtonTexture;
        public Texture2D MonsterDefenderButtonTexture;
        public Texture2D MonsterArcherPressedButtonTexture;
        public Texture2D MonsterBomberPressedButtonTexture;
        public Texture2D MonsterDefenderPressedButtonTexture;
        public Texture2D LightTexture;
        public Texture2D PowerTexture;
        public Texture2D LifeTexture;
        public Texture2D SpeedTexture;
        public Texture2D StartNewGameButton;
        public Texture2D ExitButton;
        public Texture2D RegularExitButton;
        public Texture2D HelpButton;
        public Texture2D CreditslButton;
        public Texture2D TutorialButton;

        public List<Texture2D> InstructionsTexture;
        public Texture2D NextButton;
        public Texture2D PrevButton;
        public Texture2D CloseButton;
        public Texture2D CreditsImg;


        public override void LoadContent(ContentManager content)
        {
            BlackLogoTexture = content.Load<Texture2D>("Textures/Logo/logo1");
            WhiteLogoTexture = content.Load<Texture2D>("Textures/Logo/logo2");

            ResumeButtonTexture = content.Load<Texture2D>("Textures/Buttons/resume");
            ResumePressedButtonTexture = content.Load<Texture2D>("Textures/Buttons/resumePressed");
            EndTurnButtonTexture = content.Load<Texture2D>("Textures/Buttons/swap");
            EndTurnButtonPressedTexture = content.Load<Texture2D>("Textures/Buttons/swapPressed");
            CreateNewUnitButtonTexture = content.Load<Texture2D>("Textures/Buttons/new");
            CreateNewUnitPressedButtonTexture = content.Load<Texture2D>("Textures/Buttons/NewPressed");
            CreateAndPlaceButtonTexture = content.Load<Texture2D>("Textures/Buttons/createAndPlace");
            CreateAndPlacePressedButtonTexture = content.Load<Texture2D>("Textures/Buttons/createAndPlacePressed");
            GreyStoneTexture = content.Load<Texture2D>("Textures/grey-stone");
            BlackStoneTexture = content.Load<Texture2D>("Textures/black-stone");
            SliderBackgroundTexture = content.Load<Texture2D>("Textures/Slider/Slider-Background");
            SliderScrollBarTexture = content.Load<Texture2D>("Textures/Slider/Slider-ScrollBar");
            HumanPlayerTexture = content.Load<Texture2D>("Textures/Images/humanPlayer");
            MonsterPlayerTexture = content.Load<Texture2D>("Textures/Images/monsterPlayer");
            HumanPlayerSmallIconTexture = content.Load<Texture2D>("Textures/Images/humanPlayerSmallIcon");
            MonsterPlayerSmallIconTexture = content.Load<Texture2D>("Textures/Images/monsterPlayerSmallIcon");
            HumanArcherButtonTexture = content.Load<Texture2D>("Textures/Buttons/humanArcher");
            HumanBomberButtonTexture = content.Load<Texture2D>("Textures/Buttons/humanBomber");
            HumanDefenderButtonTexture = content.Load<Texture2D>("Textures/Buttons/humanDefender");
            HumanArcherPressedButtonTexture = content.Load<Texture2D>("Textures/Buttons/humanArcherPressed");
            HumanBomberPressedButtonTexture = content.Load<Texture2D>("Textures/Buttons/humanBomberPressed");
            HumanDefenderPressedButtonTexture = content.Load<Texture2D>("Textures/Buttons/humanDefenderPressed");
            MonsterArcherButtonTexture = content.Load<Texture2D>("Textures/Buttons/monsterArcher");
            MonsterBomberButtonTexture = content.Load<Texture2D>("Textures/Buttons/monsterBomber");
            MonsterDefenderButtonTexture = content.Load<Texture2D>("Textures/Buttons/monsterDefender");
            MonsterArcherPressedButtonTexture = content.Load<Texture2D>("Textures/Buttons/monsterArcherPressed");
            MonsterBomberPressedButtonTexture = content.Load<Texture2D>("Textures/Buttons/monsterBomberPressed");
            MonsterDefenderPressedButtonTexture = content.Load<Texture2D>("Textures/Buttons/monsterDefenderPressed");
            PowerTexture = content.Load<Texture2D>("Textures/Resources/power");
            LightTexture = content.Load<Texture2D>("Textures/Resources/Torch");
            SpeedTexture = content.Load<Texture2D>("Textures/Resources/speed");
            LifeTexture = content.Load<Texture2D>("Textures/Resources/life");
            CancelButtonTexture = content.Load<Texture2D>("Textures/Buttons/cancel");
            StartNewGameButton = content.Load<Texture2D>("Textures/Buttons/StartNewGame");
            CreditslButton = content.Load<Texture2D>("Textures/Buttons/Credits");
            RegularExitButton = content.Load<Texture2D>("Textures/Buttons/regularExit");
            ExitButton = content.Load<Texture2D>("Textures/Buttons/Exit");
            HelpButton = content.Load<Texture2D>("Textures/Buttons/Help");
            TutorialButton = content.Load<Texture2D>("Textures/Buttons/Tutorial");

            WalkButtonTexture = content.Load<Texture2D>("Textures/Buttons/walk");
            WalkPressedButtonTexture= content.Load<Texture2D>("Textures/Buttons/walkPressed");

            ShootButtonTexture = content.Load<Texture2D>("Textures/Buttons/shoot");
            ShootPressedButtonTexture = content.Load<Texture2D>("Textures/Buttons/shootPressed");

            DismissButtonTexture = content.Load<Texture2D>("Textures/Buttons/dismiss");
            DismissPressedButton = content.Load<Texture2D>("Textures/Buttons/dismissPressed");

            NextButton = content.Load<Texture2D>("Textures/Buttons/instNext");
            PrevButton = content.Load<Texture2D>("Textures/Buttons/instPrev");
            CloseButton = content.Load<Texture2D>("Textures/Buttons/close");
            CreditsImg = content.Load<Texture2D>("Instructions/credits");

            InstructionsTexture = new List<Texture2D>();
            for (int i = 1; i <= 5; i++)
            {
                InstructionsTexture.Add(content.Load<Texture2D>("Instructions/instructions" + i));
            }


        }


        public override void Initialize()
        {
            //todo 
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void _Update(GameTime gameTime, BFGame game)
        {
            //todo check LastKnowedChangedLoopIndex
            //if (CurrentUIControl.IsChangedSince(ScreenManager.CurrentScreen.ChangedIn()))
            //{

            //}
            //ScreenManager.CurrentScreen.Property.Update(gameTime);
        }


        public override void Draw(GameTime gameTime, BFGame game)
        {
        }

        public void ChangeFocousedUIControl(AbstractUIControl abstractUIControl)
        {
            if (CurrentFocuseOn != null)
                CurrentFocuseOn.RemoveFocus();

            if (abstractUIControl != null)
            {
                CurrentFocuseOn = abstractUIControl;
                CurrentFocuseOn.AddFocus();
            }
        }
    }
}